package com.yuexun.dhdoctor.module.personalPlan.presenter.impl;


import com.yuexun.dhdoctor.config.AppConfig;
import com.yuexun.dhdoctor.module.personalPlan.bean.MyShareBean;
import com.yuexun.dhdoctor.module.personalPlan.model.IMyShareModel;
import com.yuexun.dhdoctor.module.personalPlan.presenter.IMySharePresenter;
import com.yuexun.dhdoctor.module.personalPlan.ui.view.IMyShareView;

import java.util.Map;

import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by work-jx on 2016/9/13.
 */
public class MySharePresenter implements IMySharePresenter {
    private IMyShareView view;
    private IMyShareModel model;

    //记录Log
//    private final Logger log = ProUtil.getLogger(LoginPresneter.class);

    public MySharePresenter(IMyShareModel model, IMyShareView view) {
        this.model = model;
        this.view = view;
    }

    @Override
    public void getMyShareList(Map<String, String> praise) {
        model.getMyShareList(praise)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<MyShareBean>() {

                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        view.PullDownRefreshState(AppConfig.DOWNLOAD_NETERROR);
                    }

                    @Override
                    public void onNext(MyShareBean myShareBean) {
                        if (myShareBean.getStatus().equals("200")) {
                            view.PullDownRefreshState(AppConfig.DOWNLOAD_SUCCESS);
                            view.showMyShareList(myShareBean);
                        } else {
                            view.PullDownRefreshState(AppConfig.DOWNLOAD_NETERROR);
                        }
                    }
                });
    }
}
